<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
        	var pMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.procurement');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			
			var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
			
			var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
			
			var ctYesnoStore = new Ext.data.Store({
                reader: new Ext.data.XmlReader({
                    record: 'item',
                    id: 'code',
                    totalRecords: 'itemTotal'
                }, ['code', 'description']),
                data: ctYesnoXmlLoader.getXml()
            });
			
			var isFinishedCombo = new Ext.form.ComboBox({
                fieldLabel: pMessage.get('ui.procurement.isfinished'),
                id: 'isFinished',
                name: 'isFinished',
                editable: false,
                store: ctYesnoStore,
                valueField: 'code',
                displayField: 'description',
                triggerAction: 'all',
                emptyText: message.get('message.combo.pleaseselect'),
                selectOnFocus: true,
                mode: 'local'
            });
			
			Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
			
				var procurementForm = new Ext.FormPanel({
                    labelAlign: 'left',
					url: '../../servlet/ProcurementServlet?action=1',
			        frame:true,
			        title: pMessage.get('ui.procurement.edittitle'),
			        bodyStyle:'padding:5px 5px 5px 5px;margin-top: 2px;',
			        width: '100%',
					labelWidth: 120,
					reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'name',
                        mapping: 'name'
                    }, {
                        name: 'isFinished',
                        mapping: 'isFinished'
                    }, {
                        name: 'comment',
                        mapping: 'comment'
                    }]),
			        items: [{
	                        id: 'id',
	                        name: 'id',
	                        xtype: 'hidden'
                    	},{
							layout: 'column',
							items: [{
								columnWidth:.5,
				                layout: 'form',
								items: [{
									xtype:'textfield',
				                    fieldLabel: pMessage.get('ui.procurement.name'),
				                    name: 'name',
				                    anchor:'86%',
									allowBlank: false,
                        			blankText: message.get('message.edit.noblank'),
									maxLength: 64,
									tabIndex: 1
								}]
							},{
								columnWidth:.5,
				                layout: 'form',
								items: [isFinishedCombo]
							}]
                    },{
                        fieldLabel: message.get('message.edit.comment'),
                        name: 'comment',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
                    }],
			
			        buttons: [{
			            text: message.get('message.edit.save'),
						handler: function(){
                            if (procurementForm.getForm().isValid()) {
								
								document.getElementsByName('isFinished')[0].value = isFinishedCombo.getValue();
								
                                procurementForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        procurementForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
			        },{
						text: message.get('message.edit.reset'),
						handler: function(){
							procurementForm.getForm().reset();
						}
					},{
			            text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'procurement_list.html?startPage=' + startPage;
                            }else {
                                window.location = 'procurement_list.html';
                            }
                        }
			        }]
			    });
				
				procurementForm.render('procurement');
			
				if (idValue != null) {
					procurementForm.getForm().load({
							url:'../../servlet/ProcurementServlet?action=3&id=' + idValue, 
							waitMsg:Ext.LoadMask.prototype.msg, 
							success: function(form, action){
								
							}
					});
				}
			});
        
        </script>
    </head>
    <body>
    	<div id="procurement"></div>
    </body>
</html>
